{% extends 'base.html' %}
{% load static %}

{% block title %}{{ movie.title }} - 电影院票务管理系统{% endblock %}

{% block content %}
<div class="row">
    <!-- 电影海报 -->
    <div class="col-md-4 mb-4">
        <img src="{% if movie.poster %}{{ movie.poster.url }}{% else %}{% static 'images/default-poster.jpg' %}{% endif %}" 
             class="img-fluid movie-poster" alt="{{ movie.title }}">
    </div>
    
    <!-- 电影信息 -->
    <div class="col-md-8">
        <div class="movie-info mb-4">
            <h1 class="mb-3">{{ movie.title }}</h1>
            <div class="row mb-3">
                <div class="col-md-6">
                    <p><i class="fas fa-user me-2"></i><strong>导演：</strong>{{ movie.director }}</p>
                    <p><i class="fas fa-users me-2"></i><strong>主演：</strong>{{ movie.actors }}</p>
                    <p><i class="fas fa-tag me-2"></i><strong>类型：</strong>{{ movie.genre }}</p>
                </div>
                <div class="col-md-6">
                    <p><i class="fas fa-clock me-2"></i><strong>时长：</strong>{{ movie.duration }}分钟</p>
                    <p><i class="fas fa-calendar me-2"></i><strong>上映日期：</strong>{{ movie.release_date|date:"Y年m月d日" }}</p>
                    <p><i class="fas fa-star me-2"></i><strong>评分：</strong>{{ avg_rating|floatformat:1 }}</p>
                </div>
            </div>
            <div class="rating-stars mb-3">
                {% for i in "12345" %}
                    {% if forloop.counter <= avg_rating %}
                        <i class="fas fa-star"></i>
                    {% else %}
                        <i class="far fa-star"></i>
                    {% endif %}
                {% endfor %}
                <span class="ms-2">({{ reviews.count }}条评论)</span>
            </div>
            <p class="mb-0"><strong>简介：</strong>{{ movie.description }}</p>
        </div>
        
        <!-- 场次信息 -->
        {% if screenings %}
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="mb-0"><i class="fas fa-calendar-alt me-2"></i>场次信息</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        {% for screening in screenings %}
                            <div class="col-md-6 col-lg-4 mb-3">
                                <div class="card h-100">
                                    <div class="card-body text-center">
                                        <h6 class="card-title">{{ screening.hall.name }}</h6>
                                        <p class="card-text text-muted">{{ screening.hall.hall_type }}</p>
                                        <p class="card-text">
                                            <i class="fas fa-clock me-1"></i>
                                            {{ screening.start_time|date:"m月d日 H:i" }}
                                        </p>
                                        <p class="card-text">
                                            <i class="fas fa-yen-sign me-1"></i>
                                            <strong class="text-primary">¥{{ screening.price }}</strong>
                                        </p>
                                        {% if user.is_authenticated %}
                                            <a href="{% url 'book_ticket' screening.id %}" class="btn btn-primary btn-sm">
                                                <i class="fas fa-ticket-alt me-1"></i>购票
                                            </a>
                                        {% else %}
                                            <a href="{% url 'login' %}" class="btn btn-outline-primary btn-sm">
                                                <i class="fas fa-sign-in-alt me-1"></i>登录购票
                                            </a>
                                        {% endif %}
                                    </div>
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        {% else %}
            <div class="alert alert-info">
                <i class="fas fa-info-circle me-2"></i>暂无场次信息
            </div>
        {% endif %}
    </div>
</div>

<!-- 评论区域 -->
<div class="row mt-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0"><i class="fas fa-comments me-2"></i>观众评论</h5>
                {% if user.is_authenticated %}
                    <button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#reviewModal">
                        <i class="fas fa-plus me-1"></i>写评论
                    </button>
                {% endif %}
            </div>
            <div class="card-body">
                {% if reviews %}
                    {% for review in reviews %}
                        <div class="border-bottom pb-3 mb-3">
                            <div class="d-flex justify-content-between align-items-start">
                                <div>
                                    <h6 class="mb-1">{{ review.user.username }}</h6>
                                    <div class="rating-stars mb-2">
                                        {% for i in "12345" %}
                                            {% if forloop.counter <= review.rating %}
                                                <i class="fas fa-star"></i>
                                            {% else %}
                                                <i class="far fa-star"></i>
                                            {% endif %}
                                        {% endfor %}
                                    </div>
                                    <p class="mb-1">{{ review.comment }}</p>
                                    <small class="text-muted">{{ review.created_at|date:"Y年m月d日 H:i" }}</small>
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-comment-slash fa-3x text-muted mb-3"></i>
                        <p class="text-muted">暂无评论，快来发表第一条评论吧！</p>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 评论模态框 -->
{% if user.is_authenticated %}
<div class="modal fade" id="reviewModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">写评论</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form method="post" action="{% url 'add_review' movie.id %}">
                {% csrf_token %}
                <div class="modal-body">
                    <div class="mb-3">
                        <label class="form-label">评分</label>
                        {{ review_form.rating }}
                    </div>
                    <div class="mb-3">
                        <label class="form-label">评论内容</label>
                        {{ review_form.comment }}
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">提交评论</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endif %}
{% endblock %} 